import Dialog from '@vant/weapp/dialog/dialog';
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		username: '',
		errorusername: '',
		errorpassword: '',
		password: '',
		isAgree: false,
		focusIndex:1
	},
	onLoad(options) {

	},
	submitReg() {
		let { username, password, errorpassword, errorusername, isAgree } = this.data;
		// if(username&&password&&!errorpassword&&!errorusername)
		if (!username) this.setData({ errorusername: '手机号不能为空' });
		if (!password) this.setData({ errorpassword: '密码不能为空' });
		if (!errorpassword && !errorusername) {
			if (!isAgree) {
				Dialog.alert({ title: '提示', message: '请同意协议' })
			} else {
				console.log(errorpassword, errorusername);
			}
		} else {
			Dialog.alert({ title: '提示', message: '请输入正确的手机号和密码' })
		}
	},
	checkUsername() {
		let { username } = this.data;
		// 验证手机号
		const phoneRegex = /^1[3456789]\d{9}$/;
		const isValidPhone = phoneRegex.test(username);
		console.log(isValidPhone,username);
		
		this.setData({ errorusername: isValidPhone ? '' : '请输入正确的手机号' });
	},
	checkPassword() {
		let { password } = this.data;
		// 验证密码（6-16位字母数字组合）
		const passwordRegex = /^[A-Za-z0-9]{6,16}$/;
		const isValidPassword = passwordRegex.test(password);
		this.setData({ errorpassword: isValidPassword ? '' : '请输入6-16位字母、数字组合密码' });
	},
	handleAgreeChange() {
		this.setData({ isAgree: !this.data.isAgree })
	},
	changeInput(event) {
		console.log(event);
		event.preventDefault();

		
		const nextInput = this.selectComponent('#nextInput');
		if (nextInput) {
			nextInput.focus();
		}
	},
	onBack(){
		wx.navigateBack();
	}
})